#post /watchings appid=xxx, time=xxx

module API::V3
  class Clients < Grape::API
    resource :watchings do
      params do
        optional :account_id, type: Integer
        requires :client_id, type: Integer
        requires :freq, type: String
        requires :sid, type: Integer
        requires :sid_name, type: String
        requires :seconds, type: Integer
      end
      post :times do
        if AuthToken.find_by_id(params[:client_id]) && (params[:account_id].blank? || Account.find_by_id(params[:account_id]))
          watching_param_key = ['account_id', 'client_id', 'freq', 'sid', 'sid_name', 'seconds']
          watching_param = params.select { |k, v| watching_param_key.include? k }
          watching = Watching.create watching_param
        end
        present result: true
      end
    end
  end
end